vector data - shapefiles

reading vector data into R

Using package rgdal we can use the gdal drivers to read ESRI shapefiles. As shapefiles have layers, we need to know which layer to load

library(rgdal)
## Loading required package: sp
## rgdal: version: 1.1-3, (SVN revision 594)
##  Geospatial Data Abstraction Library extensions to R successfully loaded
##  Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
##  Path to GDAL shared files: /usr/share/gdal/1.11
##  Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
##  Path to PROJ.4 shared files: (autodetected)
##  Linking to sp version: 1.2-1
library(mapview)
## Loading required package: leaflet

first we set our working directory

setwd('/home/ede/tappelhans/uni/marburg/lehre/2016/ss/PS_global_change')

then we can start working

shp_file <- "data/gadm_deu/gadm_deu.shp"

lyr <- ogrListLayers(dsn = shp_file)
lyr
## [1] "gadm_deu"
## attr(,"driver")
## [1] "ESRI Shapefile"
## attr(,"nlayers")
## [1] 1
# gadm_deu <- readOGR(dsn = shp_file,
#                     layer = lyr)
gadm_deu <- getGeoData(name = "GADM", country = "DEU", level = 1)
## Loading required package: XML
## Loading required package: RCurl
## Loading required package: bitops
## Loading required package: geosphere
## 
## Attaching package: 'osmar'
## The following object is masked from 'package:utils':
## 
##     find
## Checking rgeos availability: TRUE
## Loading required package: foreach
## Loading required package: iterators
## Loading required package: parallel
mapview(gadm_deu, color = "blue")